<?php
/**
 * @version $Id: form.php 44 2011-09-27 04:55:47Z lnmtrung $
 */

 defined('_JEXEC') or die('Restricted access'); 
 ?>

<link href="<?php echo JURI::base(true)?>/components/com_wrd/assets/css/uploadify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="<?php echo JURI::base(true)?>/components/com_wrd/assets/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="<?php echo JURI::base(true)?>/components/com_wrd/assets/js/swfobject.js"></script>
<script type="text/javascript" src="<?php echo JURI::base(true)?>/components/com_wrd/assets/js/jquery.uploadify.v2.1.4.min.js"></script>
<style>
	.uploadifyQueueItem {
	    background-color: #F5F5F5;
	    border: 2px solid #E5E5E5;
	    font: 11px Verdana,Geneva,sans-serif;
	    margin-top: 5px;
	    padding: 10px;
	    width: 300px;
	}
	
	#backgroundfile{
		width:160px;
		text-align: center;
	}

	#imagefile{
		text-align:left;
	}

	.image_prview {
	    background-color: #F5F5F5;
	    border: 2px solid #E5E5E5;
	    float: left;
	    margin: 2px;
	    padding: 5px;
	    text-align: center;
	    width: 160px;
	}
</style>
<script type="text/javascript">
	//<![CDATA[
	Joomla.submitbutton = function(pressbutton){
		if (pressbutton == 'cancel') {
			submitform( pressbutton );
			return;
		}
	}

	jQuery(document).ready(function() {
		
		
		jQuery('#image_upload').uploadify({ 
			
		    'uploader'  	: '<?php echo JURI::base(true)?>/components/com_wrd/assets/flash/uploadify.swf',
		    'script'    	: '<?php echo JURI::base(true)?>/components/com_wrd/classes/fileUploader.php',
		    'cancelImg' 	: '<?php echo JURI::base(true)?>/components/com_wrd/assets/images/cancel.png',
		    'folder'    	: '<?php echo str_ireplace('administrator', '', JURI::base(true)).'wrd' ?>',
		    'fileExt'		: '*.csv',
	    	'fileDesc'		: 'CSV Files (.csv)',
		    'auto'      	: true,
		    'scriptData'  	: {'typeupload':'transaction','userid':<?php echo $this->user->id ?>},
		    'onComplete'  	: 
			function(event, ID, fileObj, response, data) {
		    	obj = jQuery.parseJSON(response);
	        	jQuery('#imagefile').append('<div id="image_'+obj.fileid+'" class="image_prview"><div><img src="<?php echo JURI::base(true)?>/components/com_wrd/assets/images/csv.png" /></div><br><div><a onclick="remove_image('+obj.fileid+')" href="javascript:void(null)">Remove</a></div><div>');
	        	jQuery('#image_uploadUploader').hide();
	        	jQuery('#next1').show();
	        	jQuery('#next1link').attr('href', 'index.php?option=com_wrd&controller=transaction&layout=formimport&id='+obj.fileid);
			} 
		});
	
	});
	
	function remove_image(id){
		jQuery.ajax({
			url: "index.php?option=com_wrd&task=removefile",
			type: "POST",
			data: 'id='+id,
			success: function (res) {
				jQuery('#image_'+id).remove();
				jQuery('#image_uploadUploader').show();
				jQuery('#next1').hide();
			}
		});
	}
</script>

<form id="adminForm"  action="<?php echo JRoute::_("index.php?option=com_wrd")?>" method="post" name="adminForm" >
	<div class="col width-100">
	    <fieldset class="adminform">
	    	<legend><?php echo JText::_('Upload Transaction')?></legend>
			<table class="table table-striped adminlist">
				<tr>
					<td>
						<input id="image_upload" name="audio_upload" type="file" />
						<div id="imagefile"></div>
					</td>
					<td id="next1" style="display: none;" >
						<a id="next1link" href="#">
							<div style="float:left; text-align: center; font-size:20px;width: 100%;">
								<div><img style="margin-top: -22px;" src="components/com_wrd/assets/images/next.png"></div>
								<div style="float:right;">Import Transaction</div>
							</div>
						</a>
					</td>
				</tr>
            </table>
		</fieldset>
	</div>
	<input type="hidden" name="controller" value="transaction" />
	<input type="hidden" name="option" value="com_wrd" />
	<input type="hidden" name="task" value="" />
	<?php echo JHTML::_( 'form.token' ); ?>
</form>